
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="layui/css/layui.css" media="all">
<script src="layui/layui.js"></script>
</head>
<body>
<div>
	<img src="/file/moren.jpg" style="width: 400px;height: 400px" />
</div>
<button type="button" class="layui-btn" id="test1">
  <i class="layui-icon">&#xe67c;</i>上传图片
</button>
 

<script>
layui.use(['upload','jquery'], function(){
  var upload = layui.upload;
  var $ = layui.jquery;
   
  //执行实例
  var uploadInst = upload.render({
    elem: '#test1' //绑定元素
    ,url: 'product/upload.do' //上传接口
    ,done: function(res){
      //上传完毕回调
      //console.log(res)
      $("img").attr("src","/file/"+res.data);
    }
    ,error: function(){
      //请求异常回调
    }
  });
});
</script>

</body>
</html>